//
//  baseExtractGui.m
//  WebClipper
//
//  Created by Daniel Braun on 31/03/07.
//  Copyright 2007Daniel Braun http://page-appart.net, http://braun.daniel.free.fr  All rights reserved.
//

#import "baseExtractGui.h"


@implementation baseExtractGui

- (void) dealloc {
	// [parentObject release]; CAUTION parentObject not retained
	if (nibObjects) {
		unsigned int i, count = [nibObjects count];
		for (i = 0; i < count; i++) {
			NSObject * obj = [nibObjects objectAtIndex:i];
			[obj release];
		}
		[nibObjects release];
		//[name release];
	}
	[controller release];
	[view release];
	[super dealloc];
}

- (void) setParentObject:(WCExtractAction *)p
{
	parentObject=p; // CAUTION parentObject not retained
}
- (void) setupGuiController:(id)c
{
	[controller release];
	controller=[c retain];
}

- (NSView *) getView
{
	if (view) return view;
	NSString *nibName;
	nibName=[self className];
	if (parentObject) nibName=[parentObject className];
	NSNib *nib=[[NSNib alloc] initWithNibNamed:nibName bundle:nil];
	BOOL ok=[nib instantiateNibWithOwner:self topLevelObjects:&nibObjects];
	if (ok) {
		[nibObjects retain];
		NSAssert(view, @"view outlet not connected?");
#if 1
		extern id watchedObject;
		watchedObject=view;
#endif
		return view;
	}
	NSAssert(0, @"could not load nib file");
	return nil;
}

// KVO transparently work for me or for parent

- (id)valueForUndefinedKey:(NSString *)key
{
	return [parentObject valueForKey:key];
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
	[parentObject setValue:value forKey:key];
}
@end
